Programming ?
One of questions asked multiple times
in MMB community: is MMB scripting -
programming ?
And once for all times, let's give the
answer: YES !
You become a programmer the same
moment you write one line of code in
MMB.
It's nothing unusual, indeed. When you
set VCR to auto-record your favorite
show on TV - programming is done.
Writing scenario for a movie is
programming (of actors &
objects).
Even telling your children how to
write their very first letters or
instructing someone how to swim or
skate - no matter how unrelated to
computers it is - you're programming,
all the time ! As a matter of fact,
after all these centuries of natural
programming, we just recently started
to instruct machines what to do
instead of us.
Take for example some everyday
products:
They include instructions on the back,
telling what you must do with the
product:
So if these manufacturers can do some
programming, nothing stops you from
doing it:
And what's the main difference
?
You have much more powerful tool in
your hands !
Scripting Basics
Yeah, just like with any language -
there are some rules we must obey to
use it.
Compared to human languages, MMB
script is one simple &
fast-learning language.
Basic Facts
1. Scripting is done using lines
(rows): as you would type some
story (for e.g. detective story about
who killed the butler) on a
type-writer, you'll in MMB case use
keyboard to write MMB script story -
and guess what: by default, one
sentence per line :)
2. Sentence in MMB script story is
called "code line": one line
usually represents one command (there
are just a few exceptions)
3. You don't have to remember
command names ! MMB will help you
using commands without knowing their
attributes, and it'll provide help in
more ways:
-
syntax completion:
MMB keeps watching what you write
and if it finds identical command
in it's list - completes code line
with required syntax - now all you
have to do is enter parameters
specific to your project
-
right-click command list
menu: quick list of available
commands is on your right-click
mouse button - select command and
move on !
-
script wizard: using
built-in command list in script
editor, you really don't have to
remember any command name -
selection of command will show you
it's explanation and enable
entering of parameters
-
MMB help file: every
time you want extended explanation
of some MMB script command, come
here, to MMB Script Manual, and
read all about it !
4. Syntax highlighting &
formatting: MMB will automatically
colorize command parts, making entire
code easily readable. In addition to
this, it will automatically arrange
indent of code lines once you're
finished with scripting, further
enhancing code readability.
Preview of script lines
Here you see what these code lines
look like - they're rows of commands
that tell the story and depending on
situation - perform assigned
action.
In example above, story goes like
this:
After gathering all suspects in one
room, detective is ready for his final
act.
- Detective reads key evidence,
exposing the killer - "Old
grandpa"
- Although he's already prepared with
line accusing Joe for violent
act..
- After reading key evidence, he
screams:
Oh, now ! Grandpa, how could
you !
And that's it ! 9-line story &
Grandpa's going behind the bars
!
Details you can notice on preview
displayed above:
-
names (Old grandpa, Joe) are
colored red
-
Detective's thoughts (if
it's Joe / if it's Grandpa) are
colored blue
-
Detective's screaming (So it
IS / Grandpa, how could you) are
left in black color
-
indent of every line is
arranged to make story/code
reading
easier
Scripting Syntax
Commands are most important
part of code lines. Using commands,
you tell MMB what to do in line you're
writing. A kind of electronic army :
you're an officer and MMB is just a
soldier, executing your ideas !
;)
Of course - pay attention to
expressing ideas ! As a
difference from the real-life army
where command like...
Down soldier ! Gimme 50
!
...is taken for granted, resulting in
50 push-ups performed by soldier...MMB
would ask...
...50 of what !?...
Yeah, yeah, you already know how it
goes when working with these machines
- you gotta explain, specify, draw
everything to 'em and they still dare
to ask questions !
So let's see what we must do to keep
MMB quiet & kickin'...
There are more kinds of
commands.
Hey, don't run away just yet -
they're basically the same ;)
Every command comes with unique
name:
JoeIsMyName
...followed by both
parenthesis:
()
...put together, every command at
least looks like this:
JoeIsMyName
()
Are there commands like this above in
MMB ? Yes.
Are there different commands than
this above ? Yes.
Just like you can have vase with or
without flowers - you can have
commands with parameters or without
parameters.
Here's a summary of command styles
in MMB:
Command style
|
Command example
|
Without
parameters
|
CommandName()
|
With
one
parameter
|
CommandName("parameter")
|
With
more
parameters
|
CommandName("param1","param2")
|
With
variable
parameters
|
CommandName(variable1,variable2)
|
These are just general command styles
- read explanation of every command in
particular to learn what it
requires.
Parameters provide extra info
required by some commands; is it
natural to put flowers in vase ? Yes.
Is it natural for some commands to
require flowers... oops, parameters ?
Yes ;)
Long live the diversity - there are
many kinds of parameters:
Parameter style
|
Command example
|
Text
|
CommandName("Hello,
MMBers")
|
Numbers
|
CommandName("4329")
|
Object labels
|
CommandName("MyTextObject")
|
Time/Percentage
|
CommandName("60")
|
File
names/paths
|
CommandName("c:\MyVoice.mp3")
|
Fixed
parameters
|
CommandName("THIS_WINDOW")
|
You'll learn all about 'em later.
Notice how parameters are divided from
the rest of the command - using
quotes. If there are more parameters,
they're divided with commas:
CommandName("param1","param2")
Here comes another important fact
about commands and code lines:
You enter MMB script commands in
rows, one after another, and you can
enter as many lines as you like. As
long as code lines follow script
syntax, MMB won't mind having large
number of lines.
And one about code line
writing:
Writing of commands in MMB is not
case-sensitive. Meaning, you can
either write:
CommandName("param1","param2")
or:
COMMANDName("param1","param2")
MMB will eat it and automatically
adjust letter cases. This works for
command names only
(parameters/variables are
case-sensitive).
Script comments
Some people write (and draw) comments
in books, some use post-it notes...
and you'll save paper and write
comments in MMB ! Either to separate
parts of code lines, describe code
sections or even make reminders - in
Script Editor you're able to write
whatever you want under only one
condition; you must put single or
double (recommended) asterisk at
beginning of the line where you'll
write comments. It looks like
this:
** Hey ! Now I can write whatever I
want !
There's a case when comments will be
added automatically: if MMB notices
mistakes in code lines you wrote, it
won't keep bugging you about errors,
but simply "isolate" those lines using
asterisks, making them - comment
lines. Once you correct errors, simply
remove comment asterisks and MMB will
use these lines again.
In already mentioned code line
preview, you'll notice comment in the
very first line:
Script editor
Before learning about actual command
names & their usage, here's an
introduction to MMB objects that
contain script editors:
And now, mr. Editor
himself:
Here are explanations of Script
Editor options:
Option
|
Explanation
|
Editor Switch
|
Switches view between
Small Editor and Advanced
Editor (recommended while
it uses syntax
highlighting and script
wizard).
|
Copy/Paste
|
Clipboard commands for
script copy/pasting
|
Script Wizard
|
Opens list of available
MMB script commands with
explanations, giving
ability to specify
parameters. When selection
is confirmed, script line
will be inserted into
editor.
|
Open/Save
|
Enables opening &
saving of MMB scripts
using TXT and RTF
files.
|
Mouse Up & Down
Script
|
This switch opens
separate script
windows for actions
that happen either
on
By default, you enter code
in Mouse Up script.
|
Don't forget to try: right-click menu
in the script editor !
As you can see - it's an advanced
menu, not containing just
cut/copy/paste commands. Here you can
quickly reach script commands, save
& load scripts.
Another handy feature of Script Editor
is ability to edit written commands
through Script Wizard dialog box by
double-clicking on commands in
Editor:
Right ! Now you know where scripts
must be written and where you'll spend
numerous nights making project of your
life - let's take care of the script
content now !
|